#include <iostream>
#include <string>
 
using namespace std;
 
const int pos = 0;
string s = "i+(((((i*i*i*(i+i+(i/i))+i/i)))))$";
 
void eat();
void error();
void E();
void Eprime();
void T();
void Tprime();
void F();
 
void eat(){
	s = s.substr(1);
}
 
void error(){
	cout << "failed to match!" << endl;
	exit(1);
}
 
void E(){
	switch(s[pos]){
		case '$':
			break;
		case '(':
		case 'i':
			T();
			Eprime();
			break;
		default:
			error();
	}
}
 
void Eprime() {
	switch(s[pos]){
		case '$':
			break;
		case '+':
		case '-':
			eat();
			T();
			Eprime();
			break;
		case ')':
			break;
		default:
			error();
	}
}
 
void T() {
	switch(s[pos]){
		case '$':
			break;		
		case '(':
		case 'i':
			F();
			Tprime();
			break;
		default:
			error();
	}
}
 
void Tprime() {
	switch(s[pos]){
		case '$':
			break;		
		case '+':
		case '-':
		case ')':
			break;
		case '*':
		case '/':
			eat();
			F();
			Tprime();
			break;
		default:
			error();
	}
}
 
void F() {	
	switch(s[pos]){
		case '$':
			break;		
		case '(':
			eat();
			E();
			if(s[pos]==')') {eat(); break;}
			else error();
			break;
		case 'i':
			eat();
			break;
		default:
			error();
	}
}
 
int main() {
	E();
	cout << "finally s is " << s << endl;
	cout << "accepted!" <<endl;
	return 0;
}